﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace Xww.WindowsForm.App {
    public class AppContext : ApplicationContext {
        public List<Form> ActiveForms { get; private set; }
        public int FormCount { get; private set; }

        public AppContext() {
            ActiveForms = new List<Form>();
            FormCount = 0;
        }

        public Form AddForm(Form form) {
            ActiveForms.Add(form);
            FormCount++;
            form.Closed += new EventHandler(form_Closed);
            return form;
        }

        public Form AddShowForm(Form form) {
            AddForm(form);
            form.Show();
            return form;
        }
        void form_Closed(object sender, EventArgs e) {
            ActiveForms.Remove((Form)sender);
            FormCount--;
            if (FormCount == 0) {
                this.ExitThread();
            }
        }
    }
}
